package leetcode_1000;

import java.util.LinkedList;
import java.util.Queue;

import helpclass.TreeNode;

public class CheckCompletenessOfaBinaryTree_958 {
	public boolean isCompleteTree(TreeNode root) {
		if (root == null)
			return true;
		Queue<TreeNode> queue = new LinkedList<TreeNode>();
		queue.offer(root);
		out: while (!queue.isEmpty()) {
			TreeNode node = queue.poll();
			if (node.left != null)
				queue.offer(node.left);
			else {
				if (node.right != null)
					return false;
				break out;// 跳出外循环
			}
			if (node.right != null)
				queue.offer(node.right);
			else
				break out;
		}
		while (!queue.isEmpty()) {
			TreeNode node = queue.poll();
			if(node.left != null || node.right != null) return false;
		}
		return true;
	}
}
